home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / regkey10.zip / REGKEY.DOC < prev    next >
Text File  |  1992-07-19  |  14KB  |  264 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                    REGISTRATION KEY SYSTEM FOR C PROGRAMMERS
  9.                                  Version 1.00
  10.  
  11.  
  12.            (C) Copyright 1992, Brian Pirie. All Rights Reserved.
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.     You are granted permission to use an unmodified version of this code
  21.     in any program, so long as your program's documentation acknowledges
  22.     the use of this code. There is no charge for the use of this
  23.     software.
  24.  
  25.  
  26.  
  27.  
  28.     This brief document describes the accompanying files which can be
  29.     used to easily implement a registration key system in any programs
  30.     which you have written. I would encourage you to read this entire
  31.     file, prior to attempting to use this system - there is some very
  32.     important information contained withing, that may not seem obvious
  33.     prior to reading this document.
  34.  
  35.     This version of the registration key system is intended for use only
  36.     in conjuction with Turbo C(++)/Borland C++. If you are interested in
  37.     a version of this code for use with any other compiler, feel free to
  38.     contact me by any of the means listed at the end of this document.
  39.  
  40.     Using this registration key system, you can easily and quickly
  41.     generate and verify the validity of numerical registration keys that
  42.     correspond to a person who has purchased your program. Thus, when
  43.     someone who already has a shareware or demo version of your program
  44.     wishes to purchase the program, you need only send them a simple
  45.     registration key number, instead of sending an entire registered
  46.     version. You can simply use this package to generate a unique
  47.     registration key number which corresponds to the user's name (or any
  48.     other string you wish to use). The user will then be able to enter
  49.     this number into your software's configuration file / configuration
  50.     program. When your program begins, it will be able to read this
  51.     number from the configuration file, and again using this package,
  52.     determine whether it is a valid registration key corresponding to
  53.     the user's name. If the registration key is valid, your program can
  54.     switch into "registered mode", and if not, can run in its
  55.     unregistered "demo" mode.
  56.  
  57.     Unlike other registration key algorithms, this package can be used
  58.     over and over, by many different programs and programmers. Each
  59.     program written to use this package simply provides the registration
  60.     algorithm with its own unique numerical security code. This way, the
  61.     registration key for a user named "Brian Pirie" might be 4042871256
  62.     for one program, while the registration key for "Brian Pirie" could
  63.     be 1732396345 for another program.
  64.  
  65.     In order to make use of this registration key system in your
  66.     program, you must take a few simple steps when writing and compiling
  67.     your program:
  68.  
  69.     1.) First of all, you must include the "BP.H" header file in your
  70.         program. This can be accomplished by adding the line:
  71.  
  72.                #include "bp.h"
  73.  
  74.         at the beginning of your program.
  75.  
  76.     2.) Secondly, you must instruct your C compiler to link your program
  77.         with the appropriate BP?.LIB. The library you use should
  78.         correspond to the same memory model you use to compile your
  79.         program. The memory models and their corresponding library files
  80.         are listed below:
  81.  
  82.                 BPT.LIB - Tiny Memory Model
  83.                 BPS.LIB - Small Memory Model
  84.                 BPC.LIB - Compact Memory Model
  85.                 BPM.LIB - Medium Memory Model
  86.                 BPL.LIB - Large Memory Model
  87.                 BPH.LIB - Huge Memory Model
  88.  
  89.         In order to have your program linked with one of these
  90.         libraries, you can create a makefile or project file, which
  91.         lists the name of your program's .C source code file(s), along
  92.         with the filename of the appropriate libary. For more
  93.         information on doing this, refer to the manuals which came with
  94.         your compiler.
  95.  
  96.     You will now be able to make use of the registration key function.
  97.     This function's prototype is listed below:
  98.  
  99.       unsigned long bp(char *registration_string, unsigned int security_code);
  100.  
  101.     As you can see, this function accepts two parameters. The first
  102.     parameter, registration_string, is a pointer to the string which
  103.     should be used to generate the registration key. This will usually
  104.     be the name of the person who has registered (purchased) your
  105.     program. The second parameter, security_code, should be a number
  106.     between 0 and 65,535, which should be a unique value for any given
  107.     program you have written. It is this parameter that makes a user's
  108.     registration key unique for your program, and which prevents other
  109.     people who may have this package from producing registration keys
  110.     for use with your program. The bp() function will return the
  111.     registration key corresponding to the registration string and
  112.     security code, as an unsigned long integer. In your registration key
  113.     GENERATION PROGRAM, this is the value which you will display, in
  114.     order to send to the registered user. In the ACTUAL PROGRAM that the
  115.     user is registering, you will compare this value with the value
  116.     supplied by the user in your configuration file / configuration
  117.     program. If and only if these values match, your program should then
  118.     operate in "registered" mode.
  119.  
  120.     You can also make use of the included MAKEKEY program to generate
  121.     registration keys to send to registered users. Run this program by
  122.     simply typing MAKEKEY from the DOS prompt. You will then be prompted
  123.     to enter the unique security code used by your program, and the name
  124.     of the user who has registered. This program will then display the
  125.     registration key corresponding to the supplied registration string
  126.     (user's name). Again, remember that it is the security code which
  127.     prevents other people from creating registration keys for use with
  128.     your program, and as such, it is important that you keep your
  129.     program's security code confedential.
  130.  
  131.     When using this registration key system, be careful not to accept
  132.     registration strings (ie, the user's name) which are empty. The
  133.     registration system will always return the same value for an empty
  134.     string. Thus, you should check the length of the name the user has
  135.     entered, and if it is 0, automatically assume that the user is not
  136.     registered, and do not call the bp() function at all.
  137.  
  138.     The source code to the MAKEKEY program is included in the file
  139.     MAKEKEY.C. Feel free to alter this makekey program in any way you
  140.     wish. For example, you may want to create a custom version of the
  141.     MAKEKEY program for each of your programs in which you use the
  142.     registration key system. You would then be able to hard-code your
  143.     program's security code into your registration key gerneration
  144.     program, to eliminate the need of entering the security code every
  145.     time a user registers.
  146.  
  147.     As an example of the use of the registration key system, say you
  148.     have written a program, and chosen 24805 as your security code. Now,
  149.     when the user registers your program, you would use the MAKEKEY key
  150.     program to generate a registration key which corresponds to the
  151.     exact spelling and capitalization of their name, and send this
  152.     registration key to them. The user would then enter their name,
  153.     exactly how it appeared on their registration form, along with the
  154.     registration key you have sent them, into either a configuration
  155.     file or configuration program. You would then be able to read this
  156.     information from the configuration file, from within your program.
  157.     You program would then determine the registration key which would
  158.     correspond to the user's name, and compare this registration key to
  159.     the key supplied by the user. If the values match, then your program
  160.     would run in registered mode, and if the values do not match, then
  161.     your program would run in unregistered mode. Keep in mind that
  162.     registration keys used in this system are always of type unsigned
  163.     long. Below is an example of part of a program which uses the
  164.     registration key system. This program will read the registration
  165.     information from the file REGISTER.KEY, taking the first line to be
  166.     the name of the registered user, and the second line to be the
  167.     user's registration key. Remember this program uses 24805 as its
  168.     security code - you will want to change this value in any programs
  169.     you write. This is also the value you will have to supply to the
  170.     MAKEKEY program, when generating keys for use with the program
  171.     below. The source code to this program is also listed in the file
  172.     USEKEY.C.
  173.  
  174.         #include "bp.h"      // Include the registration key system header file
  175.  
  176.         #include <stdio.h>                              // Other C header files
  177.         #include <string.h>
  178.  
  179.         char registered=0;                         // 1 if registered, 0 if not
  180.         char registered_name[201];                   // Name of registered user
  181.  
  182.         main()                                         // Main program function
  183.            {
  184.            FILE *fp;                      // File pointer for REGISTER.KEY file
  185.            unsigned long supplied_key;                  // Key supplied by user
  186.            unsigned long correct_key;               // Correct registration key
  187.  
  188.            if((fp=fopen("REGISTER.KEY","r"))!=NULL)         // Try to open file
  189.               {                                                // If successful
  190.               fgets(registered_name,200,fp);             // read name from file
  191.               if(registered_name[strlen(registered_name)-1]=='\n')
  192.                  registered_name[strlen(registered_name)-1]='\0';
  193.  
  194.               fscanf(fp,"%lu",&supplied_key);             // read key from file
  195.  
  196.               fclose(fp);                                         // Close file
  197.  
  198.               correct_key=bp(registered_name,24805);   // Calculate correct key
  199.  
  200.               if(correct_key==supplied_key)  // Compare correct & supplied keys
  201.                  {                                     // If they are identical
  202.                  registered=1;      // Then switch program into registered mode
  203.                  }
  204.               }
  205.  
  206.            if(registered==1)                              // If registered mode
  207.               {                             // Display registration information
  208.               printf("This program is registered to: %s\n",registered_name);
  209.               }
  210.            else if(registered==0)                  // If not in registered mode
  211.               {                             // Display unregistered information
  212.               printf("This program is UNREGISTERED!!!\n");
  213.               }
  214.            }
  215.  
  216.     An alternative means of implementing the registration key system in
  217.     your programs is instead of sending the user a numerical value which
  218.     they enter into your program's configuration, to send them a
  219.     registration key file. This file, similar to that used in the above
  220.     program, would simply contain the user's name and registration key,
  221.     in any format you choose. Your "MAKEKEY" program would then generate
  222.     this file, and your distributed software would read this file, if
  223.     available.
  224.  
  225.     I have decided to make it my policy NOT to release the source code
  226.     for this registration key algorithm. The reason for this is simply
  227.     for the protection of yourself and anyone else wishing to use this
  228.     algorithm in their programs. If the source code to this algorithm
  229.     became widely available, it would be easier (though still next to
  230.     impossible), for someone to be able to produce false registration
  231.     keys for your program. What I can tell you about the algorithm,
  232.     though, is that it uses several steps in the generation of the
  233.     registration key. Each of these steps use a completely different
  234.     approach, in order to provide greater security. Also, the security
  235.     code provided by your program is actually broken down into several
  236.     bit-fields, each of which is used to alter the output of a different
  237.     level of the overall algorithm. As a result, the most security is
  238.     obtained by using a security code which has both high and low bits
  239.     throughout the 16-bit value. As a general rule, try to choose
  240.     security codes above 10000. Also note that the registration string
  241.     can not exceed 200 characters in length.
  242.  
  243.     In no event will I, Brian Pirie, be liable to you for any damages,
  244.     including any lost profits, lost savings, or other incidental or
  245.     consequential damages arising out of the use or inability to use
  246.     this software. While every effort has been made to make this
  247.     registration key system as secure as possible, please remember that
  248.     no such system is fool-proof, and that I can not take any
  249.     responsibility for any difficulties with this software.
  250.  
  251.     I hope you enjoy this package and find it useful. If you are having
  252.     any difficulty with this package, I would be more than happy to
  253.     provide any assistance I can offer. If you would like to get in
  254.     touch with me for any reason at all, please feel more than free to
  255.     do so by any of the following means.
  256.  
  257.     I can be contacted at -   FidoNet : 1:243/8
  258.                              InterNet : Brian.Pirie@f8.n243.z1.fidonet.org
  259.                            Data (BBS) : +1 613 526 4466
  260.                                Postal : 1416 - 2201 Riverside Dr.
  261.                                         Ottawa, Ontario
  262.                                         Canada
  263.                                         K1H 8K9
  264.